import { View } from "../../../../mvc/core/View";
import { LayerManager } from "../../../manager/LayerManager";
import { Tooltip } from "./Tooltip";
import { ObjCreate } from "../ObjCreate";
import { ItemData } from "../../../resource/info/ItemData";
import { ECategory } from "../../../../../Message/Public/ECategory";
import { Global } from "../../../../../com/gengine/global/Global";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class ClickToShowItemTip
    
    export  class ClickToShowItemTip extends View
    {
        constructor(arg1: int=-1)
        {
            super();
            if (ClickToShowItemTip._instance != null) 
            {
                throw new Error("ClickToShowItemTip 单例");
            }
            this.layer = LayerManager.toolTipLayer;
            this.initView();
            if (arg1 != -1) 
            {
                this.itemCode = arg1;
            }
            return;
        }

        protected initView(): void
        {
            this._toolTip = new Tooltip();
            this._closeBtn = ObjCreate.createGButton("", this._toolTip.width - 24, 4, 20, 18, null, "SmallCLoseBtn");
            this._closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.closeHander);
            this.addChild(this._toolTip);
            this.addChild(this._closeBtn);
            return;
        }

        public setItemCodeAndShow(arg1: int): void
        {
            this.itemCode = arg1;
            this.show();
            return;
        }

        /* internal  */closeHander(arg1: Object /* flash.events.Event */): void
        {
            hide();
            return;
        }

        public set itemCode(arg1: int)
        {
            if (this._itemCode == arg1) 
            {
                return;
            }
            this._itemCode = arg1;
            var loc1=new ItemData(arg1);
            if (loc1.category != ECategory._ECategoryMount) 
            {
                this._toolTip.data = loc1.getToolTipData();
            }
            else 
            {
                this._toolTip.data = loc1.getToolTipData(ItemData.ToolTipType_Mounts);
            }
            this._closeBtn.x = this._toolTip.width - 24;
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            var loc1=0;
            var loc2=0;
            loc1 = Global.stage.mouseX;
            loc2 = Global.stage.mouseY;
            if (loc1 > Global.stage.stageWidth - this._toolTip.width - 6) 
            {
                loc1 = loc1 - this._toolTip.width - 6;
            }
            if ((loc2 = loc2 - this._toolTip.height - 6) < 1) 
            {
                loc2 = 1;
            }
            if (loc1 < 1) 
            {
                loc1 = 1;
            }
            super.show(loc1, loc2);
            return;
        }

        public static get instance(): ClickToShowItemTip
        {
            if (ClickToShowItemTip._instance == null) 
            {
                ClickToShowItemTip._instance = new ClickToShowItemTip();
            }
            return ClickToShowItemTip._instance;
        }

        /* internal */ /* var */_toolTip: Tooltip;

        /* internal */ /* var */_closeBtn: GButton;

        /* internal */ /* var */_itemCode: int=-1;

        /* internal */ static /* var */_instance: ClickToShowItemTip;
    }
